﻿package com.calefk.core   {
	
	import flash.display.MovieClip;
	import com.calefk.core.EntitySimple;
	
	public class Temporary extends EntitySimple {
		
		private var mFunctionEndExecute:Function = null;
		private var mTotalFrames:int;
		private var mCurrentFrame:int;
		
		public function Temporary(canvas:MovieClip, nameClip:String = null, px:Number = 0, py:Number = 0,
				functionEndExecute:Function = null) {
			super(canvas, nameClip, px, py);
			mFunctionEndExecute = functionEndExecute;
			// animation
			mTotalFrames  = mClip.totalFrames;
			mCurrentFrame = 1;
			mClip.gotoAndStop(1);
		}
		
		override public function update(dt:int):void {
			if (mClip.currentFrame == mClip.totalFrames) {
				toClean = true;
				if (mFunctionEndExecute != null) {
					mFunctionEndExecute();
				}
			} else {
				mCurrentFrame++;
				mClip.gotoAndStop(mCurrentFrame);
			}
		}
		
		override public function clean():void {
			super.clean();
			mFunctionEndExecute = null;
		}
	}
}